package chapter9.javaFile.NIO;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class TestDataInputStreamDataOuputStream {

	public static void main(String[] args) {

		/**
		 * ESCRIBIENDO DATOS CON DataOutputFile
		 */
		OutputStream out = null;
		try {
			out = new FileOutputStream("dataOutputInputfile.txt");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DataOutputStream dos = new DataOutputStream(out);

		// Escribir un string
		try {
			dos.writeUTF("String");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// No hace falta cerrar ya que implementa autoclosable.

		/**
		 * LEYENDO DATOS CON DataInputStream
		 */

		InputStream in = null;
		try {
			in = new FileInputStream("dataOutputInputfile.txt");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DataInputStream dis = new DataInputStream(in);
		// Leyendo un String
		try {
			System.out
					.println("Leyendo String con el método DataInputStream.readUTF(): "
							+ dis.readUTF());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// No hace falta cerrar ya que implementa autoclosable.

	}
}
